package com.kaifamiao.www.ioDemo.do0923;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Arrays;

public class ObjectInputStreamDemo {

    public static void main(String[] args) {

        try (ByteArrayOutputStream baus = new ByteArrayOutputStream();
             ObjectOutputStream os = new ObjectOutputStream(baus);
                ){
            //写入int
            os.writeInt(123456);
            //写入string
            os.writeUTF("这是动力");
            //写入Object
            os.writeObject(Double.valueOf(123.456));

            System.out.println(Arrays.toString(baus.toByteArray()));
            System.out.println(baus.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
